package main

import (
	"fmt"
	"hash/crc32"
	"hash/crc64"
	"io"
	"qq_service/base/SMMsafe/goEncrypt"
	"qq_service/base/SMMsafe/hash"
)

func main1(){
	goEncrypt.PublicFileName="C:\\Users\\Tsinghua-yincheng\\Desktop\\day12\\public.pem"
	goEncrypt.PrivateFileName="C:\\Users\\Tsinghua-yincheng\\Desktop\\day12\\priv.pem"
	goEncrypt.GetRsaKey()
}

func main2(){
	var  mysha  hash.HashInterface
	mysha=new(hash.Mysha256)
	fmt.Println(mysha.GetStringHash("123"))
	fmt.Println(mysha.GetStringHash("123"))
	var  mysha2  hash.HashInterface
	mysha2=new(hash.Mysha2562)
	fmt.Println(mysha2.GetStringHash("123"))
}
func main3() {
	var mysha hash.HashInterface
	mysha = new(hash.Mysha256N)
	mysha.SetN(5)
	fmt.Println(mysha.GetStringHash("123"))
	mysha.SetN(6)
	fmt.Println(mysha.GetStringHash("123"))
	mysha.SetN(5)
	fmt.Println(mysha.GetStringHash("123"))

}
func main4() {
	var mysha hash.HashInterface
	mysha = new(hash.Mysha256)
	//fmt.Println(mysha.GetFileHash("C:\\Users\\Tsinghua-yincheng\\Desktop\\day12\\今日任务.txt"))
	fmt.Println(mysha.GetFiledirHashName("C:\\Users\\Tsinghua-yincheng\\Desktop\\day12\\oldcode"))
	fmt.Println(mysha.GetFiledirHashContent("C:\\Users\\Tsinghua-yincheng\\Desktop\\day12\\oldcode"))




}

func main5(){
	datastr:="1234545668"
	mycrc:=crc32.NewIEEE()
	io.WriteString(mycrc,datastr)
	fmt.Println(mycrc.Sum32())
	fmt.Println(fmt.Sprintf("%x",mycrc.Sum32()))
	//"1816466908"
}
func main6(){
	const ISO = 0xD800000000000000

	datastr:="12345456689999asdaasdadasasdsasd"
	tabISO := MakeTable(ISO)
	c := crc64.New(tabISO)
	io.WriteString(c, datastr)
	s := c.Sum64()
	fmt.Println(fmt.Sprintf("%x",s))
	//"1816466908"
}

func MakeTable(poly uint64) *crc64.Table {
	switch poly {
	case 0xD800000000000000:
		var slicing8TableISO  = makeSlicingBy8Table(makeTable(0xD800000000000000))
		return &slicing8TableISO[0]
	default:
		return makeTable(poly)
	}
}

func makeTable(poly uint64) *crc64.Table {
	t := new(crc64.Table)
	for i := 0; i < 256; i++ {
		crc := uint64(i)
		for j := 0; j < 8; j++ {
			if crc&1 == 1 {
				crc = (crc >> 1) ^ poly
			} else {
				crc >>= 1
			}
		}
		t[i] = crc
	}
	return t
}
func makeSlicingBy8Table(t *crc64.Table) *[8]crc64.Table {
	var helperTable [8]crc64.Table
	helperTable[0] = *t
	for i := 0; i < 256; i++ {
		crc := t[i]
		for j := 1; j < 8; j++ {
			crc = t[crc&0xff] ^ (crc >> 8)
			helperTable[j][i] = crc
		}
	}
	return &helperTable
}
